package com.example.demo.controller;


import com.example.demo.domian.Comment;
import com.example.demo.service.ApiCommentService;
import com.example.demo.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//WEB层
@RestController()//返回comment是能以json方式返回
@RequestMapping("Api")
public class ApiCommentController {
    @Autowired
    private CommentService commentService;

    @Autowired
    private ApiCommentService apiCommentService;



    //查询
    @GetMapping("/get/{id}")
    //PathVariable根据路径得到id
    public Comment findById(@PathVariable("id") Integer id){
        Comment comment=apiCommentService.findById(id);
        return  comment;
    }

    //更新
    @GetMapping("/update/{id}/{author}")
    public Comment updateComment(@PathVariable("id") Integer id,@PathVariable("author") String author){
        Comment comment=apiCommentService.findById(id);
        comment.setAuthor(author);
        Comment comment1=apiCommentService.updateComment(comment);
        return  comment1;
    }

    //删除
    @GetMapping("/delete/{id}")
    public  void deleteComment(@PathVariable("id")Integer id){
        apiCommentService.deleteComment(id);
        return;
    }


}
